package com.muh.service.impl;

import com.muh.entity.User1;
import com.muh.mapper.User1Mapper;
import com.muh.service.User1Service;
import jakarta.annotation.Resource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * (User1)表服务实现类
 *
 * @author makejava
 * @since 2025-07-14 16:16:55
 */
@Service("user1Service")
public class User1ServiceImpl implements User1Service {
    @Resource
    private User1Mapper user1Mapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public User1 queryById(Integer id) {
        return this.user1Mapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param user1 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<User1> queryByPage(User1 user1, PageRequest pageRequest) {
        long total = this.user1Mapper.count(user1);
        return new PageImpl<>(this.user1Mapper.queryAllByLimit(user1, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param user1 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(User1 user1) {
        int insert = this.user1Mapper.insert(user1);
        return insert;
    }

    /**
     * 修改数据
     *
     * @param user1 实例对象
     * @return 实例对象
     */
    @Override
    public User1 update(User1 user1) {
        this.user1Mapper.update(user1);
        return this.queryById(user1.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.user1Mapper.deleteById(id) > 0;
    }

    /**
     * 模糊查询
     * @param name
     * @return
     */
    @Override
    public List<User1> getUserByName(String name) {
        return this.user1Mapper.getUserByName(name);
    }

    /**
     * 批量插入
     * @param user1List
     * @return
     */
    @Override
    public int insertBatch(List<User1> user1List) {
        return this.user1Mapper.insertBatch(user1List);
    }

    /**
     * 批量修改
     * @param user1List
     * @return
     */
    @Override
    public int insertOrUpdateBatch(List<User1> user1List) {
        return this.user1Mapper.insertOrUpdateBatch(user1List);
    }
}
